require "StrUtilsAPI"
init("0", 1); --以当前应用 Home 键在右边初始化
width,height = getScreenSize()
setScreenScale(720,1280)
sysLog("width:"..width.."height:"..height)
function tap(x,y)
	touchDown(1, x, y)
	mSleep(500)
	touchUp(1, x, y) 
end
id = createHUD()     --创建一个HUD

local task = {}
task= {
	{"手指指引",1, 1, 1278, 717,"0|0|0xd09c84,8|11|0xe2af9e,10|16|0xac7a69,18|25|0xe2b39f"},
{"使用特殊物品",844, 253, 1007, 457,"0|0|0xead7b2,4|5|0xe2d0ab,15|1|0xead7b2,32|0|0xead9af"},
	{"发现红包",602, 43, 688, 137,"0|0|0xcf2424,19|-2|0x520f0d,40|-6|0xd62628,25|36|0xfbed97"}, 
	{"领红包",441, 195, 754, 508,"0|0|0x961010,38|0|0xf8cb8e,63|22|0xfef4cb,53|46|0xffe37d"}, 
	{"完成日常任务",125, 607, 275, 664,"0|0|0x508103,16|12|0x4f6e04,37|15|0x5b7707,47|15|0x5c7907"}, 
	{"离开红包界面",462, 98, 831, 166,"0|0|0x9e0718,15|-1|0xa60b18,52|4|0x963f29,85|4|0xffe88f"}, 
	{"支线任务已完成",40, 293, 323, 457,"0|0|0x02ca5f,12|3|0x01b957,30|4|0x01d765,51|2|0x01b857"},
	{"前往佣兵任务",684, 448, 868, 520,"0|0|0xf2f0dd,2|6|0xf0e1bf,10|8|0xe8d7b0,17|8|0xe7d6af,37|5|0xf6eaca,47|17|0x848d31"},
	{"接受佣兵任务",843, 575, 995, 619,"0|0|0xe9dab4,26|-2|0xd4d19c,50|-1|0xdfd6aa,67|-1|0xfce7cf"},
	{"穿戴装备",866, 387, 996, 449,"0|0|0xc07c30,10|3|0xb8772d,65|5|0xb6742c,75|15|0xa06529"},
	{"主线任务",38,288,278,420,"0|0|0xf7f6b9,7|3|0xa6730c,0|14|0xe8dc62,7|22|0xaf7e0b"},
	{"领取佣兵任务",42, 303, 288, 449,"0|0|0xd18d00,9|-4|0xbd7c0f,20|2|0xd18f00,34|3|0x834801"},
	{"佣兵任务",949, 568, 1120, 627,"0|0|0x588a02,0|17|0x496a04,29|27|0x5a7a08,82|13|0x466a04"},
	{"完成支线任务",39, 220, 292, 461,"0|0|0x08db6e,16|1|0x04e06d,36|2|0x07de6e,39|2|0x01d565"}, 
	{"退出副本",564, 560, 721, 610,"0|0|0x593f20,15|2|0x583f20,41|10|0x5f4627,86|-3|0x5b4120"}, 
	{"右上角关闭",1171, 0, 1279, 50,"0|0|0x311409,8|6|0x36150a,16|11|0x3b170c,28|13|0xa3958a"}, 
	{"限时任务",819, 445, 927, 488,"0|0|0x455d03,16|8|0x415603,40|-6|0x466503,64|-11|0x486c00"},
	{"跳过剧情",1189, 11, 1358, 59,"0|0|0xffe26c,6|-1|0xffe472,12|-7|0xffec9c"},
	{"进入副本",550, 473, 758, 519,"0|0|0x9e611e,4|4|0x93591c,118|2|0x995d1c,131|0|0x9e611e"},
	{"右上角关闭",1175, 30, 1249, 118,"0|0|0x4b0c0c,13|-6|0x3a0707,20|3|0x500d0d,11|9|0x450a0a"},
	{"点击任意位置",527, 565, 745, 609,"0|0|0xc9b187,28|0|0xdac192,51|-1|0xcab288,64|-4|0xb6a17a"},
	{"牛逼装备",554, 594, 721, 636,"0|0|0x4d7f03,8|0|0x4d7f03,64|3|0x4f750c,113|0|0x4d7f03"},
	{"解锁新章节",580, 530, 701, 567,"0|0|0x496303,8|-1|0x476303,44|-1|0x476303,82|-3|0x456403"},
	{"解锁新章节",420, 335, 861, 364,"0|0|0x765e39,21|0|0x7d623c,45|0|0xae8c5a,47|0|0xaf8d59"},
	
}

function findCurrentTask()
	for _, value in ipairs(task) do
		--x, y = findColor({value[2],value[3],value[4],value[5]}, value[6],95, 0, 0, 0)
		x, y = findColor({value[2], value[3], value[4], value[5]}, 
			value[6],
			95, 0, 0, 0)
		if x > -1 then
			toast(value[1])
			sysLog(value[1]);
			return {value[1],x,y};
		end
		mSleep(100)
	end	
	--如果什么都找不到，就返回主线任务
	return {"啥也没找到",100,100};
	
end

while true do
	mSleep(1000)
	showHUD(id,"欢迎使用牛牛脚本！",12,"0xffff0000","0xffffffff",0,100,0,228,32)      --显示HUD内容
	currentTask = findCurrentTask()
	
	if currentTask[1] == "主线任务" then
		tap(currentTask[2]+80, currentTask[3]);
	elseif currentTask[1] == "啥也没找到" then
		sysLog("啥也没有")
	elseif currentTask[1] == "离开红包界面" then
		tap(100, 100);
	else 
		tap(currentTask[2], currentTask[3]);
	end
end

